#include <iostream>
#include <string>
#include <algorithm>

const int N = 1e3 + 5;

int n, q;
std::string str;


int main() {
	std::cin >> n >> q;
	std::cin >> str;
	int ans = 0;
	while(q--) {
		int l, r; std::cin >> l >> r;
		std::string t;
		int c = 0;
		int res = 0;
		for(int i = l - 1; i < r; ++i) {
			if(c == 0 && str[i] == '0') ++c, t += '1', ++res;
			if(str[i] == '0') --c;
			else ++c;
			t += str[i];
		}
		std::reverse(t.begin(), t.end());
		c = 0;
		for(int i = 0; i < t.size(); ++i) {
			if(c == 0 && t[i] == '0') ++c, ++res;
			if(t[i] == '0') --c;
			else ++c;
		}
		//std::cout << res << "\n";
		ans ^= res;
	}
	std::cout << ans << "\n";
	return 0;
}
